﻿<template>
    <div class="l-rblock l-form-viewer" style="padding:8px;">
        <el-form
            :model="formData"
            :rules="rules"
            size="mini"
            labelPosition="right"
            labelWidth="80px"
            ref="form"
            >
            <div class="l-auto-window only-tabs">
                <el-tabs v-model="activeName" type="card">
                    <el-tab-pane class="l-tabs-container" :label="$t('主表信息')" name="tab0">
                        <el-row :gutter="0">
                            <div class="l-rblock">
                                <el-col v-if="lr_formLookAuth('fileSource_file_name')" :span="24" >
                                    <el-form-item 
                                        :label="$t('名称')" 
                                        prop="fileSource_file_name"
                                        > 
                                        <el-input :disabled="!lr_formEditAuth('fileSource_file_name')" v-model="formData.fileSource_file_name" :placeholder="$t('请输入')" >
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('fileSource_file_code')" :span="24" >
                                    <el-form-item 
                                        :label="$t('编码')" 
                                        prop="fileSource_file_code"
                                        > 
                                        <el-input :disabled="!lr_formEditAuth('fileSource_file_code')" v-model="formData.fileSource_file_code" :placeholder="$t('请输入')" >
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('fileSource_file_type')" :span="24" >
                                    <el-form-item 
                                        :label="$t('类型')" 
                                        prop="fileSource_file_type"
                                        > 
                                        <el-select :disabled="!lr_formEditAuth('fileSource_file_type')" v-model="formData.fileSource_file_type">
                                            <el-option :value="1" label="Minio"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('fileSource_file_description')" :span="24" >
                                    <el-form-item 
                                        :label="$t('备注')" 
                                        prop="fileSource_file_description"
                                        > 
                                        <el-input type="textarea"  :disabled="!lr_formEditAuth('fileSource_file_description')" :rows="5" v-model="formData.fileSource_file_description" :placeholder="$t('请输入')" />
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('fileSource_file_endpoint')" :span="24" >
                                    <el-form-item 
                                        :label="$t('源地址')" 
                                        prop="fileSource_file_endpoint"
                                        > 
                                        <el-input :disabled="!lr_formEditAuth('fileSource_file_endpoint')" v-model="formData.fileSource_file_endpoint" :placeholder="$t('请输入')" />
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('fileSource_file_directory')" :span="24" >
                                    <el-form-item 
                                        :label="$t('目录/桶')" 
                                        prop="fileSource_file_directory"
                                        > 
                                        <el-input :disabled="!lr_formEditAuth('fileSource_file_directory')" v-model="formData.fileSource_file_directory" :placeholder="$t('请输入')" />
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('fileSource_file_accessKey')" :span="12" >
                                    <el-form-item 
                                        :label="$t('账号')" 
                                        prop="fileSource_file_accessKey"
                                        > 
                                        <el-input :disabled="!lr_formEditAuth('fileSource_file_accessKey')" v-model="formData.fileSource_file_accessKey" :placeholder="$t('请输入')" />
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('fileSource_file_secretKey')" :span="12" >
                                    <el-form-item 
                                        :label="$t('密码')" 
                                        prop="fileSource_file_secretKey"
                                        > 
                                        <el-input type="password" :disabled="!lr_formEditAuth('fileSource_file_secretKey')" v-model="formData.fileSource_file_secretKey" :placeholder="$t('请输入')" />
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('fileSource_file_secretKey')" :span="24" >
                                    <el-form-item 
                                        :label="$t('密码')" 
                                        prop="fileSource_file_secretKey"
                                        >
                                        <l-fileSource-upload sourceCode="localhost"></l-fileSource-upload>
                                    </el-form-item>
                                </el-col>
                            </div>
                        </el-row>
                    </el-tab-pane>

                </el-tabs>
            </div>
        </el-form>
    </div>
</template>
<script>
const api = window.$api.fileSource.file

export default {
    data(){
        return {
            moduleCode: 'fileSource_file',
            activeName: 'tab0',
            formData: {
                fileSource_file_code: "", // 编码
                fileSource_file_name: "", // 名称
                fileSource_file_description: "", // 备注
                fileSource_file_type: 1, // 类型
                fileSource_file_endpoint: "", // 地址
                fileSource_file_directory: "", // 目录/桶
                fileSource_file_accessKey: "", // 账号
                fileSource_file_secretKey: "", // 密码
            },
            rules: {
                fileSource_file_code:[
                    { required: true, message: this.$t('请输入编码') },
                ],
                fileSource_file_name:[
                    { required: true, message: this.$t('请输入名称') },
                ],
                fileSource_file_endpoint:[
                    { required: true, message: this.$t('请输入源地址') },
                ],

            },
            
        };
    },
    computed: {
        
    },
    methods: {
        
        
        // 重置表单
        resetForm() {
            this.$formClear(this.$refs.form)
            this.activeName = 'tab0'
            
        },
        // 校验表单
        async validateForm() {
            if (!await this.$formValidateWraper(this.$refs.form)) {
                return false  
            }
            
            return true
        },
        // 设置表单数据
        setForm(data) {
            this.$setFormData(this.formData,data,'fileSource_file')

        },
        // 获取表单数据
        getForm() {
            return this.$getFormData(this.formData,'fileSource_file')

        },

        async loadFormData({ keyValue/*,params,node*/ }) {//  keyValue 流程中相当于流程processId,params 传递参数,node 流程节点
            const data = await this.$awaitWraper(api.get(keyValue))
            if (data) {
                this.setForm(data)
                return true
            }
            else {
                return false
            }
        },

        async saveForm({ keyValue, isEdit/*,code,node*/ }) {// isEdit 是否更新数据, keyValue 流程中相当于流程processId,code 表示流程中的操作码,node 流程节点
            const postData = this.getForm()
            if (isEdit) {// 编辑
                return await this.$awaitWraper(api.update(keyValue, postData))
            }
            else {// 新增
                postData.id = keyValue

                return await this.$awaitWraper(api.add(postData))
            }
        },
    }
}
</script>